package me.aartikov.alligator.commands;

import me.aartikov.alligator.animations.AnimationData;
import me.aartikov.alligator.destinations.AbilityDestination;
import me.aartikov.alligator.destinations.DialogFragmentDestination;
import me.aartikov.alligator.destinations.FragmentDestination;
import me.aartikov.alligator.exceptions.NavigationException;
import me.aartikov.alligator.exceptions.NotSupportedOperationException;
import me.aartikov.alligator.navigators.AbilityNavigator;
import me.aartikov.alligator.navigators.DialogFragmentNavigator;
import me.aartikov.alligator.navigators.FragmentNavigator;
import me.aartikov.alligator.Screen;
import me.aartikov.alligator.ScreenResult;

/**
 * Command implementation for {@code goBackTo} method of {@link OhosNavigator}.
 */
public class BackToCommand extends BaseCommand {
	private Class<? extends Screen> mScreenClass;

	private ScreenResult mScreenResult;

	private AnimationData mAnimationData;

	public BackToCommand( Class<? extends Screen> screenClass,  ScreenResult screenResult,  AnimationData animationData) {
		super(screenClass);
		mScreenClass = screenClass;
		mScreenResult = screenResult;
		mAnimationData = animationData;
	}

	@Override
	protected boolean executeForActivity(AbilityDestination destination, AbilityNavigator activityNavigator) throws NavigationException {
		activityNavigator.goBackTo(mScreenClass, destination, mScreenResult, mAnimationData);
		return true;
	}

	@Override
	protected boolean executeForFragment(FragmentDestination destination, FragmentNavigator fragmentNavigator) throws NavigationException {
		return  fragmentNavigator.goBackTo(mScreenClass, destination, mScreenResult, mAnimationData);
	}

	@Override
	protected void executeForDialogFragment(DialogFragmentDestination destination, DialogFragmentNavigator dialogFragmentNavigator) throws NavigationException {
		throw new NotSupportedOperationException("BackTo command is not supported for dialog fragments.");
	}
}
